var deleteBookId;
function showDeleteBookWin(id, status) {
    var deleteBookMarkObj = document.getElementById("deleteBookMark");
    deleteBookMarkObj.style.display = "block";
    var deleteBookWinObj = document.getElementById("deleteBookWin");
    deleteBookWinObj.style.display = "block";
    deleteBookId = id;
}

function cancelDeleteBook() {
    var deleteBookMarkObj = document.getElementById("deleteBookMark");
    deleteBookMarkObj.style.display = "none";
    var deleteBookWinObj = document.getElementById("deleteBookWin");
    deleteBookWinObj.style.display = "none";
}

function confirmDeleteBook() {
    var queryString = location.search;
    if (queryString.indexOf("?") != -1) {
        queryString = queryString.substr(1);
    }
    location.href = contextPath + "/deleteBook.action?id=" + deleteBookId + "&" + queryString;
}

function saveBook() {
    var editBookObj = document.getElementById("editBook");
    var isSubmitForm = true;

    var nameObj = document.getElementById("name");
    var bookNameValue = nameObj.value;
    if (!bookNameValue.trim()) {
        isSubmitForm = false;
        nameObj.style.border = "1px dashed #EB340A";
        document.getElementById("name-error-message").style.display = "inline";
    } else {
        nameObj.style.cssText = "border: 1px solid #858585;width: 410px;";
        document.getElementById("name-error-message").style.display = "none";
    }

    var authorObj = document.getElementById("author");
    var authorValue = authorObj.value;

    if (!authorValue.trim()) {
        isSubmitForm = false;
        authorObj.style.border = "1px dashed #EB340A";
        document.getElementById("author-error-message").style.display = "inline";
    } else {
        authorObj.style.cssText = "border: 1px solid #858585;";
        document.getElementById("author-error-message").style.display = "none";
    }

    if (isSubmitForm) {
        editBookObj.submit();
    }

}